package garden {
	import org.davekeen.flextrine.orm.PersistentCollection;
	import org.davekeen.flextrine.orm.FlextrineError;
  	import garden.Leaf;
   	import garden.Tree;
  
	[Bindable]
	public class BranchEntityBase {
		
		public var isUnserialized__:Boolean;
		
		public var isInitialized__:Boolean = true;
		
		public var isCollectionInitializedMap__:Object = new Object();
		
		[Id]
		public var id:String;
		
		public function get length():int { checkIsInitialized("length"); return _length; }
		public function set length(value:int):void { _length = value; }
		private var _length:int;
		
		[Association]
		public function get leaves():PersistentCollection { checkIsInitialized("leaves"); return _leaves; }
		public function set leaves(value:PersistentCollection):void { _leaves = value; }
		private var _leaves:PersistentCollection;
		
		[Association]
		public function get tree():Tree { checkIsInitialized("tree"); return _tree; }
		public function set tree(value:Tree):void { _tree = value; }
		private var _tree:Tree;
		
		public function BranchEntityBase() {
			leaves = new PersistentCollection();
		}
		
		public function toString():String {
			return "[Branch id=" + id + "]";
		}
		
		private function checkIsInitialized(property:String):void {
			if (!isInitialized__ && isUnserialized__)
				throw new FlextrineError("Attempt to get property '" + property + "' on unitialized Branch.  Consider using EntityManager::require or eager loading.", FlextrineError.ACCESSED_UNITIALIZED_ENTITY);
		}
		
	}

}
